#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  06-loadkeys-lv4.sh
# Version	:  1.0
# Date		:  2020/05/14
# Author	:  Lz
# Email		:  lz843723683@gmail.com
# History	:     
#             Version 1.0, 2020/05/14
# Function	:   packages - 06.测试安全四级-用户初始登录/认证的可信路径
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
LOADKEYSClean_FTLV4(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
LOADKEYSExit_FTLV4(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
LOADKEYSUSAGE_FTLV4(){
	USAGE_FTLIB "安全四级测试 - 用户初始登录/认证的可信路径"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
LOADKEYSInit_FTLV4(){
        # 调用初始化函数
	Init_FTLIB "LOADKEYSClean_FTLV4"
        # 调用用户界面函数
 	LOADKEYSUSAGE_FTLV4
}


## TODO ：用户初始登录/认证的可信路径
#
LOADKEYSTest01_FTLV4(){
	local ret="$TPASS"

        local flag="\"control alt keycode 119=SAK\"|/bin/loadkeys"
	local profile="/etc/profile"
	local rcfile="/etc/rc.local"

	cat ${profile} | grep -q "${flag}"
	if [ $? -ne 0 ];then
		# 未查询到指定字符串
		cat ${rcfile} | grep -q "${flag}"
		if [ $? -ne 0 ];then
			# 未查询到指定字符串
			echo "/etc/profile 或者 /etc/rc.local均不存在 ${flag}"
			ret="$TFAIL"
		else
			echo "cat ${rcfile}"
			cat ${rcfile} | grep "${flag}"
		fi
	else
		# 查询到指定支付传
		echo "cat ${profile}"
		cat ${profile} | grep "${flag}"
	fi

	OutputRet_FTLIB ${ret}
        RetParse_FTLIB "查看/etc/profile 或者 /etc/rc.local,存在如下内容：\"control alt keycode 119=SAK\"|/bin/loadkeys" "False"
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
LOADKEYSMain_FTLV4(){
	LOADKEYSInit_FTLV4

	LOADKEYSTest01_FTLV4

	return ${TPASS}	
}

LOADKEYSMain_FTLV4
LOADKEYSExit_FTLV4 $?
